// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

import http from './util/http'
// import store from "./store";
import store from './util/store'

Vue.use(ElementUI);
Vue.config.productionTip = false
Vue.prototype.$http = http


//在路由跳转之前判断
// to：新路由 ，from： 原路由 ，next
router.beforeEach((to,from,next)=>{
    // 判断用户是否登录，没有登录跳转到登录界面
    if(to.fullPath=="/" || sessionStorage.getItem("token")){
        console.log("登录/已登录");
        next();
    }else{
        console.log("未登录");
        next({path:"/"});
    }
})

/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    store, // 引入store
    components: { App },
    template: '<App/>',
    watch: {
        $route: function (to, from) {
            // console.log("跳转后的路径");
            // console.log(to);
            // console.log("跳转前的路径")
            // console.log(from);
            // 判断用户是否登录，没有登录跳转到登录界面
            // if (to != '/') {
            //   let token = sessionStorage.getItem('token')
            //   if (!token) {
            //     this.$router.replace({name: 'Login'})
            //   }
            // }
        }
    }
})
